require 'net/http'
require 'PownceUser.rb'

class PownceMessage
  
  attr_accessor :app_key # required in order to
  attr_accessor :from # from is a PownceUser object
  attr_accessor :to # OPTIONS 'public, all, friend_x, or set_x' where x is a user
  attr_accessor :message # string
  attr_accessor :parent_id # num
  attr_accessor :stars
  
  def initialize()
    
  end
  
  def send()
    auth = @from.username + ':' + @from.password
    apiUrl = 'http://' + auth + "@api.pownce.com/2.0/send/message.xml"
    res = Net::HTTP.post_form(URI.parse(apiUrl), { 
        'note_body' => @message, 
        'note_to' => @to, 
        'app_key' => @app_key 
      } )
    res.body
  end
  
  # must set the values of : parent_id, message, app_key
  # stars are optional
  def reply()
    auth = @from.username + ':' + @from.password
    apiUrl = 'http://' + auth + "@api.pownce.com/2.0/send/reply.xml"
    res = Net::HTTP.post_form(URI.parse(apiUrl), { 
        'reply_to' => @parent_id, 
        'note_body' => @message, 
        'stars' => @stars,
        'app_key' => @app_key 
      } )
    res.body
  end
  
end